import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView,
      beforeEnter: (to, from, next) => {
        const isAuthenticated = !!localStorage.getItem('token')
        if (!isAuthenticated) {
          next({ name: 'Login' })
        } else {
          next()
        }
      }
    },
    {
      path: '/login',
      name: 'Login',
      component: () => import('../views/Login.vue'),
    },
    {
      path: '/createuser',
      name: 'CreateUser',
      component: () => import('../views/CreateUser.vue'),
    },
    {
      path: '/my',
      name: 'MyProfile',
      component: () => import('../views/MyProfile.vue'),
    },
    {
      path: '/user-info',
      name: 'UserInfo',
      component: () => import('../views/UserInfo.vue'),
    },
    {
      path: '/address',
      name: 'AddressList',
      component: () => import('../views/AddressList.vue'),
    },
    {
      path: '/preference',
      name: 'Preference',
      component: () => import('../views/Preference.vue'),
    },
    {
      path: '/blacklist',
      name: 'Blacklist',
      component: () => import('../views/Blacklist.vue'),
    },
    // 订单相关页面
    {
      path: '/order/create',
      name: 'OrderCreate',
      component: () => import('../views/OrderCreate.vue'),
    },
    {
      path: '/order/list',
      name: 'OrderList',
      component: () => import('../views/OrderList.vue'),
    },
    {
      path: '/order/detail/:id',
      name: 'OrderDetail',
      component: () => import('../views/OrderDetail.vue'),
      props: true,
    },
    {
      path: '/order/rate/:id',
      name: 'OrderRating',
      component: () => import('../views/OrderRating.vue'),
      props: true,
    },
    {
      path: '/order/rating/:id',
      name: 'OrderRatingView',
      component: () => import('../views/OrderRatingView.vue'),
      props: true,
    },
    {
      path: '/order/complaint/:id',
      name: 'OrderComplaint',
      component: () => import('../views/OrderComplaint.vue'),
      props: true,
    },
    {
      path: '/order/complaint/detail/:id',
      name: 'OrderComplaintDetail',
      component: () => import('../views/OrderComplaintDetail.vue'),
      props: true,
    },
    {
      path: '/order/extra-fee/:id',
      name: 'OrderExtraFee',
      component: () => import('../views/OrderExtraFee.vue'),
      props: true,
    },
    {
      path: '/order/pay-result',
      name: 'OrderPayResult',
      component: () => import('../views/OrderPayResult.vue'),
    },
    // 评论相关页面（新版本，支持AI审核）
    {
      path: '/comment/audit-status',
      name: 'CommentAuditStatus',
      component: () => import('../views/CommentAuditStatus.vue'),
    },
    {
      path: '/comment/driver/:driverId',
      name: 'DriverComments',
      component: () => import('../views/DriverComments.vue'),
      props: true,
    },
    {
      path: '/comment/driver',
      name: 'DriverCommentsQuery',
      component: () => import('../views/DriverComments.vue'),
    },
    {
      path: '/comment/audit-progress',
      name: 'CommentAuditProgress',
      component: () => import('../views/CommentAuditProgress.vue'),
    },
    // 车辆管理相关路由
    {
      path: '/vehicle/register',
      name: 'VehicleRegister',
      component: () => import('../views/VehicleRegister.vue'),
    },
    {
      path: '/vehicle/list',
      name: 'VehicleList',
      component: () => import('../views/VehicleList.vue'),
    },
    {
      path: '/vehicle/edit/:id',
      name: 'VehicleEdit',
      component: () => import('../views/VehicleEdit.vue'),
      props: true,
    },

    {
      path: '/vehicle/violation',
      name: 'VehicleViolation',
      component: () => import('../views/VehicleViolation.vue'),
    },
    // 财务相关路由
    {
      path: '/finance/balance',
      name: 'DriverBalance',
      component: () => import('../views/DriverBalance.vue'),
    },
    // AI调度相关路由
    {
      path: '/dispatch/management',
      name: 'DispatchManagement',
      component: () => import('../views/DispatchManagement.vue'),
    },
    // 评价分析相关路由
    {
      path: '/evaluation/dashboard',
      name: 'EvaluationDashboard',
      component: () => import('../views/EvaluationDashboard.vue'),
    },
    {
      path: '/evaluation/list',
      name: 'EvaluationList',
      component: () => import('../views/EvaluationList.vue'),
    },
    {
      path: '/evaluation/suggestions',
      name: 'ImprovementSuggestions',
      component: () => import('../views/ImprovementSuggestions.vue'),
    },
    {
      path: '/evaluation/training',
      name: 'TrainingRecommendations',
      component: () => import('../views/TrainingRecommendations.vue'),
    },
    {
      path: '/evaluation/detail/:id',
      name: 'EvaluationDetail',
      component: () => import('../views/EvaluationDetail.vue'),
      props: true,
    },
    {
      path: '/evaluation/suggestion/detail/:id',
      name: 'SuggestionDetail',
      component: () => import('../views/SuggestionDetail.vue'),
      props: true,
    },
    {
      path: '/training/detail/:id',
      name: 'TrainingDetail',
      component: () => import('../views/TrainingDetail.vue'),
      props: true,
    },
    {
      path: '/training/driver/:driverId',
      name: 'DriverTrainingDetail',
      component: () => import('../views/DriverTrainingDetail.vue'),
      props: true,
    },
  ],
})

export default router
